package io.wins.vertx.entity;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import io.vertx.core.json.JsonArray;

public abstract class BaseEntity {

    protected String buildUpdateSql() {
        final StringBuilder sb = new StringBuilder();
        final Field[] fields = this.getClass().getDeclaredFields();
        for (final Field field : fields) {
            sb.append(field.getName()).append(" = ?, ");
        }
        sb.deleteCharAt(sb.lastIndexOf(","));
        return sb.toString();
    }

    protected JsonArray buildUpdateParam() {
        final JsonArray param = new JsonArray();
        try {
            final Field[] fields = this.getClass().getDeclaredFields();
            for (final Field field : fields) {
                field.setAccessible(true);
                param.add(field.get(this));
            }
        } catch (final IllegalAccessException e) {
            e.printStackTrace();
        }
        return param;
    }
}
